TSRM: use local-exec TLS in PIE executables#22278
Conversation
arnaud-lb
left a comment
There was a problem hiding this comment.
This looks good to me! Thank you!
I was wondering whether we could remove the tls_model attribute entirely, as when building a PIE the compiler should pick the local-exec model already. What actually happens is that it must emit initial-exec code when the TLS symbol is extern. That code is later relaxed by the linker, but still uses more instructions as relaxation must preserve the length of the code sequence.
So without the attribute the compiler emits a local-exec sequence like this:
movq _tsrm_ls_cache@gottpoff(%rip), %rax
addq %fs:0, %raxWhich gets relaxed to:
mov $0xfffffffffffffffc,%rax
mov %fs:(%rax),%eaxThis avoids the GOT load and is more efficient than the initial-exec model, but this uses more instructions than the proper local-exec sequence which we get with __attribute__((tls_model("local-exec"))):
mov %fs:0xfffffffffffffffc,%eax
second split PR from #22231 (comment)
it's a small change, but it comes free. measurement on a local x86_64-linux-gnu machine, ignore the wall time